﻿<?php
if ($level != 3) {
	echo "Bạn không có quyền vào trang này.";
	exit();
}
if($search) {
	$search 	= utf8_to_ascii($search);
	$sql_where 	= "WHERE singer_name_ascii LIKE '%".$search."%'";
}
$num = $mysql->query("SELECT * FROM ".$tb_prefix."singer $sql_where");
$total = $mysql->num_rows($num);
if($total) {
	$m_per_page =	30;
	if (!$pg) $pg = 1;
	$sql = "SELECT * FROM ".$tb_prefix."singer $sql_where ORDER BY singer_id DESC LIMIT ".(($pg-1)*$m_per_page).",".$m_per_page;
	$query = $mysql->query($sql);
		while($row = $mysql->fetch_array($query)) {
			$singer_ID		=	$row['singer_id'];
			$singer_NAME	=	$row['singer_name'];
			$singer_IMG		=	$row['singer_img'];
			$singer_IMG 	=   ($singer_IMG)?"<img src=".$singer_IMG." width=50 height=50>":'';
			$view_pages 	= admin_viewpages($total,$m_per_page,$pg);	
			$singer_HTML   .=	"<tr><td><input class=checkbox type=checkbox id=checkbox onclick=docheckone() name=checkbox[] value=$singer_ID></td><td class=fr><b><a href=?act=singer&mode=edit&id=".$singer_ID.">".$singer_NAME."</a></b></td><td class=fr_2 align=center>".$singer_IMG."</td></tr>";
		}
}
if(!$total) {
	$singer_HTML = "<tr><td></td><td align=center>Chưa có ca sỹ</td></tr>";
}
elseif ($_POST['do']) {
	$arr = $_POST['checkbox'];
	if (!count($arr)) die('Error');
	if ($_POST['selected_option'] == 'del') {
		$in_sql = implode(',',$arr);
		$mysql->query("DELETE FROM ".$tb_prefix."singer WHERE singer_id IN (".$in_sql.")");
		echo "<script language='JavaScript'>{ window.parent.location='?act=list_singer' }</script>";
	}
}
include("templates/list_singer.html");
?>